package leetcode.code0712;

import leetcode.IDebug;

public class Solution2 implements IDebug {

	public int minimumDeleteSum(String s1, String s2) {
		char[] cs1 = s1.toCharArray();
		char[] cs2 = s2.toCharArray();
		int len1 = cs1.length;
		int len2 = cs2.length;
		int[][] dp = new int[len1 + 1][len2 + 1];
		for (int i = 0; i <= len1; i++) {
			int c1 = i == 0 ? 0 : cs1[i - 1];
			for (int j = 0; j <= len2; j++) {
				int c2 = j == 0 ? 0 : cs2[j - 1];
				if (c1 == c2) {
					dp[i][j] = i == 0 || j == 0 ? 0 : dp[i - 1][j - 1];
				} else {
					dp[i][j] = i == 0 ? j == 0 ? 0 : dp[i][j - 1] + c2
							: j == 0 ? dp[i - 1][j] + c1 : Math.min(dp[i - 1][j] + c1, dp[i][j - 1] + c2);
				}
			}
		}
		return dp[len1][len2];
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		System.out.println((int) 's');

//		try {
//			String str = null;
//			System.out.println(str.equals("123"));
//		} catch (Exception e) {
//			System.out.println("error");
//			return;
//		} finally {
//			System.out.println("finally");
//		}
		System.out.println("123\n123");
		StringBuffer sb = new StringBuffer();
		sb.append("123//n123");
		System.out.println();
	}

}
